<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    const obj = {
        name: '张三',
        family: {
            father: '李四'
        },
        hobby: ['唱歌']
    }

    function cloneDeep(oldobj) {
        const newobj = Array.isArray(oldobj) ? [] : {}
        for (let k in oldobj) {
            if (typeof oldobj[k] === 'object'){
                newobj[k] = cloneDeep(oldobj[k])
            }
            else {
                newobj[k] = oldobj[k]
            }
        }
        return newobj
    }

    const newobj = cloneDeep(obj)
    console.log(newobj)
</script>
</body>
</html>